package com.xinqi.modules.chat.chat.friend.controller;

import com.xinqi.common.base.response.R;
import com.xinqi.common.core.utils.MessageUtils;
import com.xinqi.common.satoken.utils.LoginHelper;
import com.xinqi.modules.chat.chat.friend.dto.req.ChatFriendListQueryDTO;
import com.xinqi.modules.chat.chat.friend.dto.req.ChatFriendUpdateDTO;
import com.xinqi.modules.chat.chat.friend.dto.rsp.ChatFriendBlackListDto;
import com.xinqi.modules.chat.chat.friend.dto.rsp.ChatFriendDetailsResultDTO;
import com.xinqi.modules.chat.chat.friend.dto.rsp.ChatFriendListTypeResultDTO;
import com.xinqi.modules.chat.chat.friend.dto.rsp.ChatFriendResultDTO;
import com.xinqi.modules.chat.chat.friend.service.ChatFriendService;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * WEB -- 黑名单/好友
 *
 * @version V1.0
 * @Title:
 * @ClassName: com.xinqi.modules.chat.chat.friend.controller.web.ChatFriendWebController.java
 * @Description:
 * @Copyright 星齐科技（云南）有限公司 - Powered By 技术部
 * @author: yyzhen
 * @date: 2023/3/10 11:21
 */
@Validated
@RestController
@RequestMapping("/friend")
@RequiredArgsConstructor
public class ChatFriendTempController {
    private final ChatFriendService chatFriendService;

    /**
     * 我的黑名单
     *
     * @Title:
     * @MethodName: blacklist
     * []
     * @Return com.xinqi.common.base.response.R
     * @Exception
     * @Description:
     * @author: yyzhen
     * @date: 2023/3/9 15:55
     */
    @Operation(summary = "我的黑名单")
    @GetMapping("blacklist")
    public R<List<ChatFriendBlackListDto>> blacklist(@RequestParam(name = "keywords", required = false) String keywords) {
        ChatFriendBlackListDto query = new ChatFriendBlackListDto();
        query.setUserId(LoginHelper.getUserId());
        query.setKeywords(keywords);
        return R.ok(chatFriendService.blacklist(query));
    }

    /**
     * 移除黑名单
     *
     * @Title: 移除黑名单
     * @MethodName: removeBlack
     * [friendId]
     * @Return com.xinqi.common.base.response.R
     * @Exception
     * @Description:
     * @author: yyzhen
     * @date: 2023/3/7 14:14
     */
    @Operation(summary = "移除黑名单")
    @GetMapping("/removeBlack/{userId}")
    public R removeBlack(@NotNull(message = "{chat.friend.userId.not.blank}") @PathVariable Long userId) {
        if (chatFriendService.removeChatFriendBlack(userId, LoginHelper.getUserId())) {
            return R.ok(MessageUtils.message("chat.friend.remove.black.success"));
        } else {
            return R.fail(MessageUtils.message("chat.friend.remove.black.fail"));
        }
    }

    /**
     * 加入黑名单
     *
     * @Title:
     * @MethodName: addBlack
     * [userId]
     * @Return com.xinqi.common.base.response.R
     * @Exception
     * @Description:
     * @author: yyzhen
     * @date: 2023/3/24 13:46
     */
    @Operation(summary = "加入黑名单")
    @GetMapping("/addBlack/{userId}")
    public R addBlack(@NotNull(message = "{chat.friend.userId.not.blank}") @PathVariable Long userId) {
        if (chatFriendService.addChatFriendBlack(userId, LoginHelper.getUserId())) {
            return R.ok(MessageUtils.message("chat.friend.add.black.success"));
        } else {
            return R.fail(MessageUtils.message("chat.friend.add.black.fail"));
        }
    }

    @Operation(summary = "检查是否是好友")
    @GetMapping("/check/{friendId}")
    public R<ChatFriendResultDTO> friedCheck(@NotNull(message = "{chat.friend.friendId.not.blank}") @PathVariable("friendId") Long friendId) {
        return R.data(chatFriendService.friedCheck(LoginHelper.getUserId(), friendId));
    }

    @Operation(summary = "获取好友列表-星标分类")
    @GetMapping("/list-star-mark")
    public R<ChatFriendListTypeResultDTO> friedListStarMark() {
        ChatFriendListTypeResultDTO friedR = chatFriendService.friedListStarMark(LoginHelper.getUserId());
        return R.data(friedR);
    }

    @Operation(summary = "获取好友列表")
    @PostMapping("/list")
    public R<List<ChatFriendDetailsResultDTO>> friedList(@RequestBody ChatFriendListQueryDTO dto) {
        dto.setOperationUserId(LoginHelper.getUserId());
        return R.data(chatFriendService.friedList(dto));
    }

    @Operation(summary = "好友基本信息")
    @GetMapping("/details/{friendId}")
    public R<ChatFriendDetailsResultDTO> friedDetails(@NotNull(message = "{chat.friend.friendId.not.blank}") @PathVariable("friendId") Long friendId) {
        ChatFriendDetailsResultDTO friendDetails = chatFriendService.friedDetails(LoginHelper.getUserId(), friendId);
        return R.data(friendDetails);
    }

    @Operation(summary = "设置好友")
    @PutMapping("/set")
    public R<Boolean> setFriend(@Validated @RequestBody ChatFriendUpdateDTO dto) {
        Boolean setStatus = chatFriendService.setFriend(LoginHelper.getUserId(), dto);
        return R.data(setStatus);
    }

    @Operation(summary = "删除好友")
    @DeleteMapping("/delete/{friendId}")
    public R<Boolean> deleteFriend(@NotNull(message = "{chat.friend.friendId.not.blank}") @PathVariable("friendId") Long friendId) {
        return R.data(chatFriendService.deleteFriend(LoginHelper.getUserId(), friendId));
    }

}
